import { book, tag } from "@/type/books";
import { BooksState } from "@/type/store/books";
import { cloneDeep } from "lodash";
const initState: BooksState = {
  bookInfo: {
    id: undefined,
    bookName: "",
    icon: "",
    monthStartDay: 1,
    tagVOList: [],
    tagList: [],
  },
};

export default {
  namespaced: true,
  state: cloneDeep(initState),
  mutations: {
    SET_BOOKINFO(state: BooksState, bookInfo: book) {
      state.bookInfo = bookInfo;
    },
    SET_BOOKID(state: BooksState, id: number | unknown) {
      state.bookInfo.id = id;
    },
    SET_BOOKNAME(state: BooksState, bookName: string) {
      state.bookInfo.bookName = bookName;
    },
    SET_BOOKICON(state: BooksState, icon: string) {
      state.bookInfo.icon = icon;
    },
    // 新增编辑删除之后tagList
    SET_TAGLIST(state: BooksState, tagList: tag[]) {
      state.bookInfo.tagList = tagList;
    },
    // 新增编辑删除之后tagVOList
    SET_TAGVOLIST(state: BooksState, tagVOList: tag[]) {
      state.bookInfo.tagVOList = tagVOList;
    },
    CLEAR_BOOKS_STATE(state: BooksState) {
      const noClearKeys: any = [];
      for (const key in state) {
        if (!noClearKeys.includes(key)) {
          (state as any)[key] = (initState as any)[key]
        }
      }
    },
  },
  actions: {},
};
